package com.bristua.barcode.order.controller;

import com.bristua.barcode.common.bean.Result;
import com.bristua.barcode.common.enums.CommonCode;
import com.bristua.barcode.common.exception.BizException;
import com.bristua.barcode.common.util.HandleResultUtil;
import com.bristua.barcode.common.util.JsonUtil;
import com.bristua.barcode.customer.model.condition.SendOrderParams;
import com.bristua.barcode.order.biz.SendOrderBiz;
import com.bristua.barcode.order.enums.OrderCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2019/8/9 0009.
 */
@RestController
public class SendOrderController {

    private static final Logger logger = LoggerFactory.getLogger(SendOrderController.class);

    @Autowired
    private SendOrderBiz sendOrderBiz;

    @PostMapping(value = "/customer/send/order")
    public Result sendOrder(@RequestBody SendOrderParams sendOrderParams){
        logger.info("下单参数:"+ JsonUtil.toJson(sendOrderParams));
        if(StringUtils.isEmpty(sendOrderParams.getGoodsId())){
            throw new BizException(CommonCode.PARAMS_FAIL.getCode(),CommonCode.PARAMS_FAIL.getMsg());
        }

        if(StringUtils.isEmpty(sendOrderParams.getMoney())){
            throw new BizException(CommonCode.PARAMS_FAIL.getCode(),CommonCode.PARAMS_FAIL.getMsg());
        }

        if(StringUtils.isEmpty(sendOrderParams.getOrderNo())){
            throw new BizException(CommonCode.PARAMS_FAIL.getCode(),CommonCode.PARAMS_FAIL.getMsg());
        }
        if(StringUtils.isEmpty(sendOrderParams.getSign())){
            throw new BizException(CommonCode.PARAMS_FAIL.getCode(),CommonCode.PARAMS_FAIL.getMsg());
        }

        if(StringUtils.isEmpty(sendOrderParams.getTimestap())){
            throw new BizException(CommonCode.PARAMS_FAIL.getCode(),CommonCode.PARAMS_FAIL.getMsg());
        }
        return HandleResultUtil.dataResult(OrderCode.SEND_ORDER_SUCCESS.getCode(),OrderCode.SEND_ORDER_SUCCESS.getMsg(),sendOrderBiz.sendOrder(sendOrderParams));
    }
}
